<%--
  Created by IntelliJ IDEA.
  User: 袁飞
  Date: 2020/3/11/011
  Time: 20:17
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>华晨机械公司erp系统|进销存</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/bssmanager/plugins/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/bssmanager/dist/css/adminlte.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/bssmanager/plugins/toastr/toastr.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/bssmanager/plugins/sweetalert2-theme-bootstrap-4/bootstrap-4.min.css">
    <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
    <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
    <jsp:include page="../navbar.jsp"></jsp:include>
    <jsp:include page="../sidebar.jsp"></jsp:include>
    <div class="content-wrapper">
        <div class="content-header">
            <div class="container-fluid">
                <div class="row mb-2">
                    <div class="col-sm-6">
                        <h1 class="m-0 text-dark">Starter Page</h1>
                    </div>
                    <div class="col-sm-6">
                        <ol class="breadcrumb float-sm-right">
                            <li class="breadcrumb-item"><a href="#">Home</a></li>
                            <li class="breadcrumb-item active">Starter Page</li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>
        <div class="content contents">
            <div class="container-fluid">
                <h3 class="mt-4 mb-4">当前员工</h3>
                <div class="row">
                    <div class="col-sm-4">
                        <div class="card card-widget widget-user">
                            <div class="widget-user-header text-white" style="background: url('${pageContext.request.contextPath}/bssmanager/dist/img/photo1.png') center center;">
                                <h3 class="widget-user-username text-right">Elizabeth Pierce</h3>
                                <h5 class="widget-user-desc text-right">Web Designer</h5>
                            </div>
                            <div class="widget-user-image">
                                <img class="img-circle" src="${pageContext.request.contextPath}/bssmanager/dist/img/user1-128x128.jpg" alt="User Avatar">
                            </div>
                            <div class="card-footer">
                                <div class="row">
                                    <div class="col-sm-4 border-right">
                                        <div class="description-block">
                                            <h5 class="description-header">3,200</h5>
                                            <span class="description-text">SALES</span>
                                        </div>
                                    </div>
                                    <div class="col-sm-4 border-right">
                                        <div class="description-block">
                                            <h5 class="description-header">13,000</h5>
                                            <span class="description-text">FOLLOWERS</span>
                                        </div>
                                    </div>
                                    <div class="col-sm-4">
                                        <div class="description-block">
                                            <h5 class="description-header">35</h5>
                                            <span class="description-text">PRODUCTS</span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12" style="clear: both;">
                        <div class="card card-primary card-outline">
                            <div class="card-header">
                                <h3 class="card-title">
                                    <i class="fas fa-edit"></i>
                                    任务表
                                </h3>
                            </div>
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-md-2 col-sm-2">
                                        <div class="nav flex-column nav-tabs h-100" id="vert-tabs-tab" role="tablist" aria-orientation="vertical">
                                            <a class="nav-link" id="vert-tabs-home-tab" data-toggle="modal" data-target="#modal-info" role="tab">进货</a>
                                            <a class="nav-link" id="vert-tabs-profile-tab cancel" data-toggle="pill" href="#vert-tabs-profile" role="tab" aria-controls="vert-tabs-profile" aria-selected="false">退货</a>
                                        </div>
                                    </div>
                                    <div class="col-md-10 col-sm-10">
                                        <div class="tab-content" id="vert-tabs-tabContent">
                                            <div class="tab-pane fade" id="vert-tabs-profile" role="tabpanel" aria-labelledby="vert-tabs-profile-tab">
                                                <div class="col-md-10">
                                                        <h3 class="card-title">订单列表</h3>
                                                        <table class="table table-bordered">
                                                            <thead>
                                                            <tr>
                                                                <th>orderId</th>
                                                                <th>类目</th>
                                                                <th>商家姓名</th>
                                                                <th>商家电话</th>
                                                                <th>商家地址</th>
                                                                <th>状态</th>
                                                                <th>createTime</th>
                                                                <th>updateTime</th>
                                                                <th>操作</th>
                                                            </tr>
                                                            </thead>
                                                            <tbody>
                                                            <c:forEach items="${pageInfo.list}" var="order">
                                                                <tr>
                                                                    <td>${order.orderId}</td>
                                                                    <td>${order.orderType}</td>
                                                                    <td>${order.businessName}</td>
                                                                    <td>${order.businessPhone}</td>
                                                                    <td>${order.businessAddr}</td>
                                                                    <c:choose>
                                                                        <c:when test="${order.orderStatus==0}"><td>新订单</td></c:when>
                                                                        <c:when test="${order.orderStatus==1}"><td>已取消</td></c:when>
                                                                        <c:otherwise><td>已完结</td></c:otherwise>
                                                                    </c:choose>
                                                                    <td><fmt:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
                                                                    <td><fmt:formatDate value="${order.updateTime}" pattern="yyyy-MM-dd HH:mm:ss" /></td>
                                                                    <td><button type='button' class='btn btn-block bg-gradient-danger'>
                                                                        <a href="javascript:cancelOrder(${order.id});" style="color: #fff">Cancel</a>
                                                                    </button></td>
                                                                </tr>
                                                            </c:forEach>
                                                            </tbody>
                                                        </table>
                                                    <div class="card-footer clearfix">
                                                        <ul class="pagination pagination-sm m-0 float-right" id="paging">
                                                            <li class='page-item disabled'><a class='page-link' href='javascript:void(0);'>&laquo;</a></li>
                                                            <c:forEach begin="1" end="${pageInfo.pages}" step="1" var="p">
                                                                <li class='page-item'><a class='page-link' href='/ERP/bss/order/getAll?pageNum=${p}&flag=1' >${p}</a></li>
                                                            </c:forEach>
                                                            <li class='page-item disabled'><a class='page-link' href='javascript:void(0);'>&raquo;</a></li>
                                                        </ul>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <jsp:include page="../controlsidebar.jsp"></jsp:include>
    <jsp:include page="../foot.jsp"></jsp:include>
    <div id="sidebar-overlay"></div>
    <div class="modal fade" id="modal-info" style="display: none; padding-right: 17px;" aria-modal="true">
        <div class="modal-dialog">
            <div class="modal-content bg-info">
                <div class="modal-header">
                    <h4 class="modal-title">进货</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true"><p class="nav-icon fas fa-window-close"></p></span></button>
                </div>
                <form role="form" id="myForm1">
                    <div class="modal-body">
                        <div class="form-group">
                            <label>类目</label>
                            <select class="form-control" id="orderType" name="orderType">
                                <c:forEach items="${categoryList}" var="category">
                                    <option value="${category.categoryType}">${category.categoryName}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <div class="form-group">
                            <label>商品</label>
                            <select class="form-control" id="product" name="productId">

                            </select>
                        </div>
                        <div class="form-group">
                            <label>商家</label>
                            <select class="form-control" id="company" name="companyId">
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="num">数量</label>
                            <input type="text" class="form-control" id="num" name="num" placeholder="数量">
                        </div>
                        <div class="form-group">
                            <label for="totalPrice">总价</label>
                            <span>￥</span><input id="totalPrice" name="totalPrice" style="border: none" />
                        </div>
                    </div>
                    <div class="modal-footer justify-content-between">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-success swalDefaultSuccess" id="addSuccess" data-dismiss="modal">添加</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="${pageContext.request.contextPath}/bssmanager/plugins/jquery/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/bssmanager/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="${pageContext.request.contextPath}/bssmanager/dist/js/adminlte.min.js"></script>
<script src="${pageContext.request.contextPath}/bssmanager/dist/js/demo.js"></script>
<script src="${pageContext.request.contextPath}/bssmanager/plugins/sweetalert2/sweetalert2.min.js"></script>
<script src="${pageContext.request.contextPath}/bssmanager/plugins/toastr/toastr.min.js"></script>
<script>
    var Toast = Swal.mixin({
        toast: true,
        position: 'center',
        showConfirmButton: false,
        timer: 3000
    });
    function cancelOrder(id){
        if (confirm("你确定要取消该订单吗？")){
            $.get('/ERP/bss/order/cancel',{"id":id},function () {
                Toast.fire({
                    type: 'success',
                    title: 'congratulation you success!'
                })
                location.href="/ERP/bss/order/getAll?pageNum=1&&flag=1"
            })
        }
    }
    $(function () {
        $("#addSuccess").click(function () {
            $.post({
                url:'/ERP/bss/order/addOrder',
                data:$("#myForm1").serialize(),
                success:function () {
                    location.href="/ERP/bss/order/getAll?pageNum=1&&flag=1"
                }
            })
        })
        $("#orderType").change(function () {
            $.get({
                url:'/ERP/bss/product/getProductsByCategoryType',
                data:{"categoryType":$("#orderType").val()},
                success:function (data) {
                    var str = "<option value=''>请选择...</option>";
                    for(var i=0;i<data.length;i++){
                        str += "<option value='"+data[i].productId+"'>"+data[i].productName+"</option>";
                    }
                    $("#product").html(str)
                }
            })
        })
        $("#product").change(function () {
            $.get({
                url:'/ERP/bss/company/getCompanysBycompanyType',
                data:{"companyType":$("#orderType").val()},
                success:function (data) {
                    var str = "<option value=''>请选择...</option>";
                    for(var i=0;i<data.length;i++){
                        str += "<option value='"+data[i].companyId+"'>"+data[i].companyName+"</option>";
                    }
                    $("#company").html(str)
                }
            })
        })
            $("#num").blur(function () {
                $.get({
                    url:'/ERP/bss/product/countPrice',
                    data:{"id":$("#product").val(),"num":$("#num").val()},
                    success:function (data) {
                        $("#totalPrice").val(data)
                    }
                })
            })

        $(".selected-title").each(function () {
            $(this).on("click",function () {
                if ($(this).hasClass("active")) {
                    return
                }else {
                    $(".selected-title").each(function () {
                        $(this).removeClass("active")
                    })
                    $(this).addClass("active")
                }
            })
        })
        $(".selectedA").each(function(){
            $(this).on("click",function () {
                if ($(this).hasClass("active")) {
                }else {
                    $(".selectedA").each(function () {
                        $(this).removeClass("active")
                    })
                    $(this).addClass("active")
                    var pre=$(this).attr("name")
                    $.ajax({
                        type: "GET",
                        async:false,
                        url: $(this).attr("action")+"?v="+Math.random(),
                        cache:false,
                        success: function (data) {
                            $(".content").html(data)
                            $.getScript(pre+'list.js',function(){
                            });
                        }
                    })
                }
            })
        })
    })
</script>
</body>
</html>
